/**
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package spring.cloud.tasks.api.service;

import org.springframework.web.multipart.MultipartFile;
import spring.cloud.tasks.api.database.entity.TaskConfigurationDto;
import spring.cloud.tasks.api.domain.*;
import spring.cloud.tasks.api.vo.GetTaskConfigurationVo;
import spring.cloud.tasks.api.zookeeper.ZooKeeper;

import java.io.File;
import java.util.List;
import java.util.Map;

public interface TaskService {

    void enableJob(String namespace, String jobName, String updatedBy) throws RuntimeException;

    void disableJob(String namespace, String jobName, String updatedBy) throws RuntimeException;

    void removeTask(String namespace, String jobName) throws RuntimeException;

    /**
     * 获取该作业可选择的优先Executor
     */
    List<ExecutorProvided> getExecutorProvidedList(String namespace, String jobName) throws RuntimeException;

    void setPreferList(String namespace, String jobName, String preferList, String updatedBy)
            throws RuntimeException;


    void addJob(String namespace, TaskConfiguration taskConfiguration, String createdBy) throws RuntimeException;


    int getMaxTaskNum() throws RuntimeException;

    boolean taskIncExceeds(String namespace, int maxJobNum, int inc) throws RuntimeException;

    List<TaskConfiguration> getTaskConfigurationList(String namespace) throws RuntimeException;

    List<TaskConfigurationDto> getUnSystemJobsWithCondition(String namespace, Map<String, Object> condition, int page, int size)
            throws RuntimeException;

    int countUnSystemJobsWithCondition(String namespace, Map<String, Object> condition)
            throws RuntimeException;

    int countEnabledUnSystemJobs(String namespace) throws RuntimeException;

    /**
     * @deprecated since 3.1.0，不再支持systemJob
     */
    @Deprecated
    List<String> getUnSystemJobNames(String namespace) throws RuntimeException;


    List<String> getTaskIdList(String namespace) throws RuntimeException;

    /**
     * 持久化作业到指定namespace
     */
    void saveTaskConfigurationToZooKeeperWithSetDefaultValues(String namespace, TaskConfiguration taskConfiguration) throws RuntimeException;

    /**
     * 持久化作业到特定zk上面
     */
    void saveTaskConfigurationToZooKeeperWithSetDefaultValues(TaskConfiguration taskConfiguration, ZooKeeper zooKeeper) throws RuntimeException;

    List<TaskResult> importTasks(String namespace, MultipartFile file, String createdBy)
            throws RuntimeException;

    File exportJobs(String namespace) throws RuntimeException;

    File exportSelectedJobs(String namespace, List<String> jobList) throws RuntimeException;


    TaskConfiguration getTaskConfigurationFromZooKeeper(String namespace, String jobName) throws RuntimeException;

    TaskConfiguration getTaskConfiguration(String namespace, String jobName) throws RuntimeException;

    TaskStatus getTaskStatus(String namespace, String jobName) throws RuntimeException;

    TaskStatus getTaskStatus(String namespace, TaskConfiguration taskConfiguration) throws RuntimeException;

    boolean isJobShardingAllocatedExecutor(String namespace, String jobName) throws RuntimeException;

    List<String> getExecutorIdList(String namespace, String jobName) throws RuntimeException;

    GetTaskConfigurationVo getTaskConfigurationVo(String namespace, String jobName) throws RuntimeException;

    void updateTaskConfiguration(String namespace, TaskConfiguration taskConfiguration, String updatedBy) throws RuntimeException;

    List<String> getTaskIdFromZooKeeper(String namespace) throws RuntimeException;

    void updateTaskCron(String namespace, String jobName, String cron, Map<String, String> customContext,
                        String updatedBy) throws RuntimeException;

    /**
     * 获取作业所分配的executor及先关分配信息。
     */
    List<TaskExecutor> getTaskExecutorList(String namespace, String jobName) throws RuntimeException;

    /**
     * 获取JobServer状态信息
     */
    List<TaskExecutorStatus> getTaskExecutorStatusList(String namespace, String jobName) throws RuntimeException;

    void runAtOnce(String namespace, String jobName) throws RuntimeException;

    void stopAtOnce(String namespace, String jobName) throws RuntimeException;

    /**
     * 获取作业运行状态
     */
    List<ExecutionInfo> getExecutionStatus(String namespace, String jobName) throws RuntimeException;

    /**
     * 获取运行日志
     */
    String getExecutionLog(String namespace, String jobName, String jobItem) throws RuntimeException;


}
